package com.follow.service.impl;

import com.follow.common.PageUtil;
import com.follow.dao.TbFollowVOMapper;
import com.follow.pojo.*;
import com.follow.service.TbFolVOService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2020/9/27.
 */
@Service
public class TbFolVOServiceImpl implements TbFolVOService{

    @Autowired
    private TbFollowVOMapper tbFollowVOMapper;

    public PageUtil<TbFollowVO> selectFolAll(Integer pageNum, Integer pageSize, Integer id, Integer followId, String followName, Integer departmentId, String departmentName, String principal, Integer state,Date createTime){

        PageUtil<TbFollowVO> pageUtil = new PageUtil<>();
        Integer count = tbFollowVOMapper.selectFollowCount(id,followId,followName,departmentId,departmentName,principal,state,createTime);
        pageUtil.setTotal(count);
        pageUtil.setPageNum(pageNum);
        pageUtil.setPageSize(pageSize);
        List<TbFollowVO> tbFollowVOS = tbFollowVOMapper.selectFollowAll(pageUtil.getStartNum(),pageSize,id,followId,followName,departmentId,departmentName,principal,state,createTime);
        pageUtil.setResult(tbFollowVOS);
        return pageUtil;
    }

    public TbFollowVO selectFolOne(Integer id){
        return tbFollowVOMapper.selectFolOne(id);
    }
    //查询科室
    public List<TbDepartment> selectDepartment(){
        return tbFollowVOMapper.selectDepartment();
    }
    //批量删除
    public boolean removeBeach(String[] ids) {
        int i = tbFollowVOMapper.deleteGroup(ids);
        if (i > 0) return true;
        else return false;
    }
    //查询医院
    public List<TbHospital> selectHospital(){
        return tbFollowVOMapper.selectHospital();
    }

    //查询级别
    public List<TbLevel> selectLevel(){
        return tbFollowVOMapper.selectLevel();
    }
    //查询小组
    public List<TbGroup> selectGroup(){
        return tbFollowVOMapper.selectGroup();
    }
    //添加
    public boolean addFollow(TbFollowVO tbFollowVO,String followName,String principal){

        int i = tbFollowVOMapper.addGroup(tbFollowVO);
        int s = tbFollowVOMapper.addFollowName(followName);
        int k = tbFollowVOMapper.addFollowNameId(followName,principal);
        if(i>0 && s>0 && k>0) return true;
        else return false;
    }
}
